package com.authsphere.security.common.handler;

import com.authsphere.common.result.ResponseResultUtils;
import com.authsphere.security.common.logging.LoggingAuthenticationSuccessHandler;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;

/**
 * @program: AuthSphere
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/25 10:44
 **/
public abstract class AbstractResponseAuthenticationSuccessHandler extends LoggingAuthenticationSuccessHandler {

    @Override
    protected void doAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        Object extract = extract(request, response, authentication);
        if (extract != null) {
            ResponseResultUtils.result(response, extract);
        }
    }

    protected abstract Object extract(HttpServletRequest request, HttpServletResponse response, Authentication authentication);
}
